<?php

/**
 * Header models 
 * 
 * Header models in console
 *
 * PHP Version: 1.2.3
 * 
 * @author Johari <joharijumali@gmail.com>
 */

/**
 * Class Header
 * 
 * Class Header in console models
 *
 * @author Johari <joharijumali@gmail.com>
 */

class Console_Header extends Eloquent
{

    public static $timestamps = true;
    public static $table = 'sys_navigation_header';
    public static $key = 'snh_id';
	
	/**
     * Function navpages
	 *
	 * @return navpages.
     */
	public function navpages()
	{
		return $this->has_many('Console_Link', 'snh_id');
	}

	/**
     * Function navigationdata
	 *
	 * @return navigationdata.
     */
	public static function navigationdata()
	{
		$testlist = array();
		$returndata = array();
		$navheader = Console_Header::order_by('snh_step', 'asc')->get();

		foreach ($navheader as $key => $value) {
			$returndata[$key]['header'] = $value->snh_header;
			$returndata[$key]['snh_id'] = $value->snh_id;
			$testlist = Console_Header::find($value->snh_id)->navpages()->order_by('snp_parent_step', 'asc')->get();

			foreach ($testlist as $ckey => $cvalue) {
				$parent = Console_Page::find($cvalue->smp_id);

				if (!empty($parent) && $cvalue->snp_parent == 0) {	
					$returndata[$key]['parent'][$ckey]['alias'] = $parent->smp_action_alias;
					$returndata[$key]['parent'][$ckey]['pageid'] = $cvalue->snp_id;
					$returndata[$key]['parent'][$ckey]['path'] = $parent->smp_modul.'/'.$parent->smp_controller.'/'.$parent->smp_action;

					$child = Console_Link::where('snp_parent', '=', $cvalue->snp_id)->get();
								
					if (!empty($child)) {
					
						foreach ($child as $childkey => $childvalue) {
							$childpage = Console_Page::find($childvalue->smp_id);
							$returndata[$key]['parent'][$ckey]['child'][$childkey]['alias'] = $childpage->smp_action_alias;
							$returndata[$key]['parent'][$ckey]['child'][$childkey]['childid'] = $childvalue->snp_id;
							$returndata[$key]['parent'][$ckey]['child'][$childkey]['path'] = $childpage->smp_controller.'/'.$childpage->smp_action;
						}
							
					}

				}

			}

		}

		return $returndata;
	}

}

?>